package com.zhongx.xingcd.zxxcd.controller;

import com.zhongx.xingcd.zxxcd.service.KeyWordFriendService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class KeyWordAndFriendController {
    @Autowired
    private KeyWordFriendService keyWordFriendService;
    /**
     * 跳转友情链接配置
     * @param session
     * @return
     */
    @RequestMapping("/goFriendLinks")
    public String goFriendLinks(HttpSession session) {
        return "zxxcd/admin/admin_friendlinks_manage";
    }

    /**
     * 跳转关键字配置
     * @param session
     * @return
     */
    @RequestMapping("/goKeyWord")
    public String goKeyWord(HttpSession session) {
        return "zxxcd/admin/admin_keyword_manage";
    }

    /**
     * 获取关键字信息
     * @param jsonParam
     * @return
     */
    @RequestMapping(value = "/getKeyWordInfo",method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String getKeyWordInfo(@RequestBody JSONObject jsonParam, HttpServletResponse response) {
        //System.out.println("接收的数据 "+jsonParam);
        Map map =new HashMap();
        map.put("keyword_name",jsonParam.getString("keyword_name"));
        List keyList = keyWordFriendService.getKeyword(map);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result_data_size",keyList.size());
        jsonObject.put("result_data",keyList);
        jsonObject.put("result_code",0);
        jsonObject.put("result_mes","关键字信息");
        return jsonObject.toString();
    }

    /**
     * 获得友情链接信息
     * @param jsonParam
     * @return
     */
    @RequestMapping(value = "/getFriendInfo",method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String getFriendInfo(@RequestBody JSONObject jsonParam, HttpServletResponse response) {
        //System.out.println("接收的数据 "+jsonParam);
        Map map =new HashMap();
        map.put("link_name",jsonParam.getString("link_name"));
        List keyList = keyWordFriendService.getLinkInfo(map);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result_data_size",keyList.size());
        jsonObject.put("result_data",keyList);
        jsonObject.put("result_code",0);
        jsonObject.put("result_mes","友情链接信息");
        return jsonObject.toString();
    }
    /**
     * 插入关键字信息
     * @param jsonParam
     * @return
     */
    @RequestMapping(value = "/insertKeyWordInfo",method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String insertKeyWordInfo(@RequestBody JSONObject jsonParam, HttpServletResponse response) {
        System.out.println("接收的数据 "+jsonParam);
        //List keyList = keyWordFriendService.getLinkInfo();
        JSONObject jsonObject = new JSONObject();
        //jsonObject.put("result_data",keyList);
        jsonObject.put("result_code",0);
        jsonObject.put("result_mes","友情链接信息");
        return jsonObject.toString();
    }
    /**
     * 获得友情链接信息
     * @param jsonParam
     * @return
     */
    @RequestMapping(value = "/insertFriendInfo",method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String insertFriendInfo(@RequestBody JSONObject jsonParam, HttpServletResponse response) {
        System.out.println("接收的数据 "+jsonParam);
        //List keyList = keyWordFriendService.getLinkInfo();
        JSONObject jsonObject = new JSONObject();
        //jsonObject.put("result_data",keyList);
        jsonObject.put("result_code",0);
        jsonObject.put("result_mes","友情链接信息");
        return jsonObject.toString();
    }
    /**
     * 删除关键字信息
     * @param jsonParam
     * @return
     */
    @RequestMapping(value = "/deleteKeyWordInfo",method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String deleteKeyWordInfo(@RequestBody JSONObject jsonParam, HttpServletResponse response) {
        System.out.println("接收的数据 "+jsonParam);
        //List keyList = keyWordFriendService.getLinkInfo();
        JSONObject jsonObject = new JSONObject();
        //jsonObject.put("result_data",keyList);
        jsonObject.put("result_code",0);
        jsonObject.put("result_mes","友情链接信息");
        return jsonObject.toString();
    }
    /**
     * 获得友情链接信息
     * @param jsonParam
     * @return
     */
    @RequestMapping(value = "/deleteFriendInfo",method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String deleteFriendInfo(@RequestBody JSONObject jsonParam, HttpServletResponse response) {
        System.out.println("接收的数据 "+jsonParam);
        //List keyList = keyWordFriendService.getLinkInfo();
        JSONObject jsonObject = new JSONObject();
        //jsonObject.put("result_data",keyList);
        jsonObject.put("result_code",0);
        jsonObject.put("result_mes","友情链接信息");
        return jsonObject.toString();
    }
}
